using System;
using System.Security.Principal;

namespace buildingLib.security
{
    [Serializable()]
    public class MPrincipal:
     Csla.Security.BusinessPrincipalBase
    {
     private MPrincipal(IIdentity identity)
      : base(identity) { }

    public static bool Login(string username, string password)
    {       
      MIdentity identity = 
        MIdentity.GetIdentity(username, password);
      
      if (identity.IsAuthenticated)
      {
        MPrincipal principal = new MPrincipal(identity);
        Csla.ApplicationContext.User = principal;
      }
      return identity.IsAuthenticated;
    }

    public static void Logout()
    {
      MIdentity identity = MIdentity.UnauthenticatedIdentity();
      MPrincipal principal = new MPrincipal(identity);
      Csla.ApplicationContext.User = principal;
    }

    public override bool IsInRole(string role)
    {
      MIdentity identity = (MIdentity)this.Identity;
      return identity.IsInRole(role);
    }
    }
}
